var chapterEarth;
//var kmlUrl="http://dl.dropbox.com/u/3961427/gtugs.kml";
var kmlUrl="http://geolabs.com.br/pulse/gtugs.kml";
//var kmlUrl="http://www.gtugs.org/gtugs.kml";

var lastMouseMov;

function addChapterToChapterList(id, chapter) {
}

function postProcessChapterList() {
}



function maybeInitializeChapterEarth() {
	if (!chapterEarth) {
	  chapterEarth=earthInstance("map3dBig", function(ok, instance) {
	      postProcessPlacemarks(instance);
        if (ok) {
          google.earth.addEventListener(instance.getGlobe(), 'mousemove', somethingHappened);
		  somethingHappened();
		  setInterval(inactiveCheck, 5000);
        }
	    }, 
		{spin: false, mouseNavigation: true, flyToSpeed: 0.6, initialView: function(instance) {
		    var cam = instance.getView().copyAsCamera(instance.ALTITUDE_ABSOLUTE);
			cam.setAltitude(12000000);
			instance.getView().setAbstractView(cam);
		}});
	  chapterEarth.init(kmlUrl);
	}
}

function inactiveCheck() {
  var _now=new Date().getTime();
  if (_now-lastMouseMov>20000) {
    showEventVisualization();
  }
}
function somethingHappened() {
  lastMouseMov=new Date().getTime();
}

function postProcessPlacemarks(instance) {
  if (typeof(instance)!='undefined') {
    var placemarks=instance.getElementsByType("KMLPlacemark");
   for (var i=0; i<placemarks.getLength(); i++) {
     changeClickListener(placemarks.item(i), instance);
   }
  }
}

function changeClickListener(pl, ge) {
	google.earth.addEventListener(pl, 'click', function(event) {
	  event.preventDefault();
	  var content = pl.getDescription();
	  var balloon = ge.createHtmlStringBalloon('');
	  balloon.setFeature(pl);
      balloon.setContentString(content);
      ge.setBalloon(balloon);
	});
}
/*
var continents={'Argentina':'South America',
'Armenia':'Europe',
'Australia':'Oceania',
'Austria':'Europe',
'Belarus':'Europe',
'Belgium':'Europe',
'Brazil':'South America',
'Brunei':'Asia',
'Canada':'North America',
'China':'Asia',
'Colombia':'South America',
'Czech Republic':'Europe',
'Denmark':'Europe',
'Egypt':'Africa',
'El Salvador':'South America',
'Ethiopia':'Africa',
'France':'Europe',
'Germany':'Europe',
'Ghana':'Africa',
'Greece':'Europe',
'Guatemala':'South America',
'Honduras':'South America',
'India':'Asia',
'Indonesia':'Asia',
'Ireland':'Europe',
'Israel':'Asia',
'Italy':'Europe',
'Japan':'Asia',
'Jordan':'Asia',
'Kazakhstan':'Europe',
'Kenya':'Africa',
'Lebanon':'Asia',
'Liberia':'Africa',
'Malawi':'Africa',
'Malaysia':'Asia',
'Mexico':'South America',
'Netherlands':'Europe',
'Nigeria':'Africa',
'Palestinian Territories':'Asia',
'Peru':'South America',
'Philippines':'Asia',
'Portugal':'Europe',
'Romania':'Europe',
'Russia':'Asia',
'Senegal':'Africa',
'Serbia':'Europe',
'Singapore':'Asia',
'Slovakia':'Europe',
'South Africa':'Africa',
'South Korea':'Asia',
'Spain':'Europe',
'Sri Lanka':'Asia',
'Sweden':'Europe',
'Syria':'Asia',
'Taiwan':'Asia',
'Tanzania':'Africa',
'Thailand':'Asia',
'Turkey':'Europe',
'Uganda':'Africa',
'Ukraine':'Europe',
'United Arab Emirates':'Asia',
'United Kingdom':'Europe',
'United States':'North America',
'Uruguay':'South America',
'Venezuela':'South America'};


function getContinentForCountry(countryName) {
  return continents[countryName] || 'unknown';
}


*/
